<!DOCTYPE html>
<html ng-app="app" ng-controller="indexCtrl">

	<head lang="en">
		<meta charset="UTF-8">
		<meta http-equiv="Expires" content="0">
		<meta http-equiv="Pragma" content="no-cache">
		<meta http-equiv="Cache-control" content="no-cache">
		<meta http-equiv="Cache" content="no-cache">
		<title>广告投放-广告主</title>
		<link rel="shortcut icon" href="favicon.ico" type="image/x-icon" id="favicon">
		<link rel="stylesheet" href="css/layer.css" />

		<link rel="stylesheet" href="lib/bootstrap/css/bootstrap.min.css" />
		<link rel="stylesheet" href="css/bootstrap-datetimepicker.min.css" />
		<link rel="stylesheet" href="css/base.css" />
		<link rel="stylesheet" href="modules/agent/agQualification/agQualification.css" />
		<link rel="stylesheet" href="../../oem/css/common.css" />
		<style>
			.hide {
				display: none;
			}
			
			.layui-upload-file {
				opacity: 0;
				position: absolute;
				top: 0px;
				left: 0;
				z-index: -9;
			}
		</style>
	</head>

	<body>
		<div class="nav_top">
			<div class="logo fl" id="logo">
			</div>
			<ul class="nav_list fl">

				<li>
					<a href="agentIndex.html">首页</a>
				</li>

				<li>

					<a href="active.html" class="toFirstSub">投放管理</a>
					<ul class="nav_dropdown" style="width: 1903px;">

						<li>
							<a href="active.html">活动管理</a>
						</li>

						<li>
							<a href="order.html">订单管理</a>
						</li>

						<li>
							<a href="creative.html">素材信息</a>
						</li>

						<li>
							<a href="audiences.html">监测管理</a>
						</li>

					</ul>
				</li>

				<li>

					<a href="baoBiao.html" class="toFirstSub">报表中心</a>
					<ul class="nav_dropdown" style="width: 1903px;">

						<li>
							<a href="baoBiao.html">效果报表</a>
						</li>
						<li ng-if="permission.view['合约报表'].sub['效果报表']" class="ng-scope">
							<a href="./heyuebaobiao.html" ui-sref-active="active" ui-sref="agent.report.effect({'activeID':'0','activeName':'0','orderID':'0','orderName':'0'})" class="">合约报表</a>
						</li>
					</ul>
				</li>

				<li>
					<a href="baseInfo.html" class="toFirstSub active">系统管理</a>
					<ul class="nav_dropdown" style="width: 1903px;">

						<li>
							<a href="baseInfo.html">基本信息</a>
						</li>

						<li>
							<a href="qualifications.html">资质管理</a>
						</li>

					</ul>
				</li>

				<li>

					<a href="caiwu.html" class="toFirstSub">财务管理</a>
					<ul class="nav_dropdown" style="width: 1903px;">

						<li>
							<a href="caiwu.html">财务信息</a>
						</li>

					</ul>
				</li>

			</ul>
			<div class="user">
				<div class="user-avatar"></div>
				<div class="user-info">
					<p></p>
					<p></p>
				</div>
				<ul class="user-list">
					<li class="ng-binding">余额：</li>
					<li>退出登录</li>
				</ul>
			</div>
		</div>

		<div class="qualification-page page ng-scope">
			<h3 class="page-title">资质管理</h3>
			<div class="form">
				<div class="form-title">
					<span class="form-title-font">基本信息</span>
					<i class="form-title-edit ng-scope" onclick="change()"></i>
				</div>
				<div id="zhanShi">
					<div class="form-group">
						<label>营业执照主体名称</label>
						<div class="form-static" id="t1"></div>
					</div>
					<div class="form-group">
						<label>品牌名称</label>
						<div class="form-static" id="t2"></div>
					</div>
					<div class="form-group">
						<label>公司网址</label>
						<div class="form-static" id="t3"></div>
					</div>
					<div class="form-group">
						<label>营业执照</label>
						<a class="form-link" id="t4" onclick="showPhoto(this)"></a>
					</div>
					<div class="form-group">
						<label>ICP</label>
						<a class="form-link" id="t5" onclick="showPhoto(this)"></a>
					</div>
					<div class="form-group">
						<label>组织机构完税证</label>
						<a class="form-link" id="t6" onclick="showPhoto(this)" ></a>
					</div>
					<div class="form-group">
						<label>组织机构资质</label>
						<a class="form-link" id="t7" onclick="showPhoto(this)" ></a>
					</div>
					<div class="form-group">
						<label>网络文化经营许可证</label>
						<a class="form-link"  id="t8" onclick="showPhoto(this)" ></a>
					</div>
					<div class="form-group">
						<label>法人身份证</label>
						<a class="form-link" id="t9" onclick="showPhoto(this)"></a>
					</div>
					<div class="form-group">
						<label>医疗机构执业许可证</label>
						<a class="form-link" id="t10" onclick="showPhoto(this)"></a>
					</div>
					<div class="form-group">
						<label>医疗广告审查许可证</label>
						<a class="form-link" id="t11" onclick="showPhoto(this)"></a>
					</div>
					<div class="form-group">
						<label>品牌资质</label>
						<a class="form-link" id="t12" onclick="showPhoto(this)"></a>
					</div>
				</div>
				<div id="bianJi" class="hide">

					<div class="form-group">
						<label><span class="star">*</span>营业执照主体名称</label>
						<input type="text" id="txt1" class="form-control ng-pristine ng-untouched ng-valid ng-scope ng-not-empty ">
					</div>
					
						<div class="form-group">
							<label><span class="star">*</span>品牌名称</label>
							<input type="text" id="txt2" class="form-control ng-pristine ng-untouched ng-valid ng-scope ng-not-empty">
						</div>
						
						<div class="form-group">
							<label><span class="star">*</span>公司网址</label>
							<input type="text"  class="form-control ng-pristine ng-untouched ng-valid ng-scope ng-not-empty" id="xiaoYan_url">
							<button class="dsp-btn btn-green" onclick="checkUrl()">校验</button>

						</div>
						<div class="form-group layui-upload">
							<label><span class="star">*</span>营业执照</label>
							<button class="dsp-btn btn-green layui-btn" id="upload3">选择文件</button>
							<div class="form-details-img hide" onclick="showPhoto(this)"></div>
						</div>
						<div class="form-group layui-upload">
							<label>ICP</label>
							<button class="dsp-btn btn-green" id="upload4">选择文件</button>
							<div class="form-details-img hide" onclick="showPhoto(this)"></div>
						</div>
						<div class="form-group layui-upload">
							<label> 组织机构完税证</label>
							<button class="dsp-btn btn-green" id="upload5">选择文件</button>
							<div class="form-details-img hide" onclick="showPhoto(this)"></div>
						</div>
						<div class="form-group layui-upload">
							<label>组织机构资质</label>
							<button class="dsp-btn btn-green" id="upload6">选择文件</button>
							<div class="form-details-img hide" onclick="showPhoto(this)"></div>
						</div>
						<div class="form-group layui-upload">
							<label>网络文化经营许可证</label>
							<button class="dsp-btn btn-green" id="upload7">选择文件</button>
							<div class="form-details-img hide" onclick="showPhoto(this)"></div>

						</div>
						<div class="form-group layui-upload">
							<label>法人身份证</label>
							<button class="dsp-btn btn-green" id="upload8">选择文件</button>
							<div class="form-details-img hide" onclick="showPhoto(this)"></div>
						</div>
						<div class="form-group layui-upload">
							<label>医疗机构执业许可证</label>
							<button class="dsp-btn btn-green" id="upload9">选择文件</button>
							<div class="form-details-img hide" onclick="showPhoto(this)"></div>
						</div>
						<div class="form-group layui-upload">
							<label>医疗广告审查许可证</label>
							<button class="dsp-btn btn-green" id="upload10">选择文件</button>
							<div class="form-details-img hide" onclick="showPhoto(this)"></div>
						</div>
						<div class="form-group layui-upload">
							<label>品牌资质</label>
							<button class="dsp-btn btn-green" id="upload11">选择文件</button>
							<div class="form-details-img hide" onclick="showPhoto(this)"></div>
						</div>
						<div class="form-group">
							<label>其他资质：</label>
							<p class="form-static"><a class="btn-font" href="javascript:addzz(); ">添加其他资质</a><small>最多添加20个资质</small></p>
						</div>
						<div id= "qua"></div>
						<div class="btn-group ">
							<button class="dsp-btn btn-green " onclick="saveQualification() ">保存</button>
							<button class="dsp-btn btn-red " onclick="upLoad() ">关闭</button>
						</div>
					</div>
				</div>
			</div>

	</body>

</html>
<script src="../res1.hubcloud.com.cn/lib/jquery/jquery.min.js "></script>
<script src="js/layui.js " charset="utf-8 "></script>
<script src="js/js_1.js"></script>
<script src="js/commen.js?rand=v1.0.54 "></script>

<script>
	$(function() {
		aptitudeQueryInfo()
		$('.user').on('click', function() {
			$(this).toggleClass('hover');
		})

		$('.user').mouseleave(function() {
			$(this).removeClass('hover');
		});

		$('.dropdown').on('click', function() {

			if($(this).hasClass("open ")) {
				$(this).removeClass('open');
			} else {
				$('.dropdown').removeClass('open');
				$(this).addClass('open');
			}
		})
		layui.use('upload', function() {
			var $ = layui.jquery,
				upload = layui.upload;
			//普通图片上传
			var uploadInst = upload.render({
				elem: '.layui-upload button',
				url: url + "/common/upload ",
				before: function(obj) {
					//预读本地文件示例，不支持ie8
					obj.preview(function(index, file, result) {
//						console.log(index+','+file+','+result)
						
//						$('#demo1').attr('src', result); //图片链接（base64）
//						$('#demo1').parent().removeClass("hide ");
					});
				},
				done: function(res) {
					//如果上传失败
					if(res.code > 0) {
						return layer.msg('上传失败');
					}
					//上传成功
					var that = uploadInst.config.item[0];
					$(that).attr("data-n",res.data[0].url)
					$(that).next().next().removeClass('hide');
					var str = "url("+res.data[0].url+")no-repeat";
					$(that).next().next().attr("data-url",res.data[0].url)
					$(that).next().next().css({'background':str,"background-size":"100% 100%"})
				},
				error: function() {
					//演示失败状态，并实现重传
					var demoText = $('#demoText');
					demoText.html(
						'<span style="color: #FF5722; ">上传失败</span> <a class="layui-btn layui-btn-xs demo-reload ">重试</a>'
					);
					demoText.find('.demo-reload').on('click', function() {
						uploadInst.upload();
					});
				}
			});
		})
	})
	//查询资质管理信息
	function aptitudeQueryInfo(){
		let token = sessionStorage.getItem("token");
		$.ajax({
			url: url + "/advertiser/adAptitude/aptitudeQueryInfo",
			type: "GET",
			dataType: 'json',
			async:false,
			contentType: "application/json",
			useDefaultXhrHeader: false,
			//		请求头加上X-Token 
			 beforeSend: function(XMLHttpRequest) {
				//		token 为页面所获取
				XMLHttpRequest.setRequestHeader("X-Token", token); 
			},
			success: function(result) {
			
				$("#t1").html(result.data.adUserInfo.adBrand);
				$("#t2").html(result.data.adUserInfo.adComapyName);
				$("#t3").html(result.data.adUserInfo.adComapyUrl);
				
				
				if(!result.data.adUserInfoQualified.businessUrl){
					$("#t4").html('暂未上传').css('color',"#19bc98");
				}else{
					$("#t4").attr("data-url",result.data.adUserInfoQualified.businessUrl).html("查看");
				}
				if(!result.data.adUserInfoQualified.icpUrl){
					$("#t5").html('暂未上传').css('color',"#19bc98");
				}else{
					$("#t5").attr("data-url",result.data.adUserInfoQualified.icpUrl).html("查看");
				}
				if(!result.data.adUserInfoQualified.taxCertificateUrl){
					$("#t6").css('color',"#19bc98").html('暂未上传');
				}else{
					$("#t6").attr("data-url",result.data.adUserInfoQualified.taxCertificateUrl).html("查看");
				}
				if(!result.data.adUserInfoQualified.organizationQualificationUrl){
					$("#t7").css('color',"#19bc98").html('暂未上传');
				}else{
					$("#t7").attr("data-url",result.data.adUserInfoQualified.organizationQualificationUrl).html("查看");
				}
				if(!result.data.adUserInfoQualified.networkLicenseUrl){
					$("#t8").css('color',"#19bc98").html('暂未上传');
				}else{
					$("#t8").attr("data-url",result.data.adUserInfoQualified.networkLicenseUrl).html("查看");
				}
				if(!result.data.adUserInfoQualified.legalPersonUrl){
					$("#t9").css('color',"#19bc98").html('暂未上传');
				}else{
					$("#t9").attr("data-url",result.data.adUserInfoQualified.legalPersonUrl).html("查看");
				}
				if(!result.data.adUserInfoQualified.medicalInstitutionUrl){
					$("#t10").css('color',"#19bc98").html('暂未上传');
				}else{
					$("#t10").attr("data-url",result.data.adUserInfoQualified.medicalInstitutionUrl).html("查看");
				}
				if(!result.data.adUserInfoQualified.medicalAdvertisementUrl){
					$("#t11").css('color',"#19bc98").html('暂未上传');
				}else{
					$("#t11").attr("data-url",result.data.adUserInfoQualified.medicalAdvertisementUrl).html("查看");
				}
				if(!result.data.adUserInfoQualified.brandQualification){
					$("#t12").css('color',"#19bc98").html('暂未上传');
				}else{
					$("#t12").attr("data-url",result.data.adUserInfoQualified.brandQualification).html("查看");
				}
				
				
			},
			err: function(err) {
				console.log(err)
				alert("请求失败");
				
			}
		});
	}
//	打开编辑
	function change() {
		var a = $("#zhanShi").hasClass('hide')
		if(a){
			$('#zhanShi').removeClass("hide");
			$('#bianJi').addClass("hide ");
		}else{
			$('#zhanShi').addClass("hide");
			$('#bianJi').removeClass("hide ");
		}
	}

	// 显示相片弹框
	function showPhoto(obj) {
		var url = $(obj).attr('data-url')
		if(url) {
			layer.photos({photos: {"data": [{"src": url}]},anim:5});
		}
	}
	//校验
	function checkUrl() {
		let url = $("#xiaoYan_url ").val();
		var reg = /^https?:\/\//;
		if(!reg.test(url)) return layer.msg("公司网址格式不正确！格式为http://xxxxx ");
		window.open(url)
	}
	//关闭
	function upLoad() {
		$('#zhanShi').removeClass("hide ");
		$('#bianJi').addClass("hide ");
		aptitudeQueryInfo()
	}
//	添加资质
	var zzlist = [];
	 var nobj={
      "key": "",
      "value": ""
    }
	 function addzz(){
	 	zzlist.push(nobj)
		nobj={"key": "","value": ""}
		addlist()
	 }
	function addlist(){
		var data=zzlist;
		var html="";
		for(var i=0;i<data.length;i++){
			html+= '<div class="form-group ng-scope scop">';
			html+='<label>资质名称：</label>';
			html+='<input type="text" class="form-control ng-pristine ng-untouched ng-valid ng-empty" onchange="opt(this,'+i+')" value="'+data[i].key+'">';
			html+=' <span>资质文件</span>';
            html+='<button class="dsp-btn btn-green chbtn" data-n="'+i+'">选择文件</button>';   
            html+=' <a href="javascript:;" class="btn-font" onclick="deleteQua('+i+')">删除</a> ';
            if(data[i].value){
            	html+='<div class="form-details-img" onclick="showPhoto(this)" data-url="'+data[i].value+'"'
            }else{
            	html+='<div class="form-details-img hide" onclick="showPhoto(this)"'
            }
            html+=' style="background: rgba(0, 0, 0, 0) url('+data[i].value+') no-repeat scroll 0% 0% / 100% 100%;"></div></div>';
		}
		$("#qua").html(html)
		layui.use('upload', function() {
			var $ = layui.jquery,
				upload = layui.upload;
			//普通图片上传
			var uploadInst = upload.render({
				elem: '.scop .chbtn',
				url: url + "/common/upload ",
				before: function(obj) {
					//预读本地文件示例，不支持ie8
					obj.preview(function(index, file, result) {});
				},
				done: function(res) {
					//如果上传失败
					if(res.code > 0) {
						return layer.msg('上传失败');
					}
					//上传成功
					var that = uploadInst.config.item[0];
					var ind = $(that).attr('data-n')
					window.zzlist[ind].value = res.data[0].url
					var str = "url("+res.data[0].url+")no-repeat";
					$(that).next().next().next().removeClass('hide');
					$(that).next().next().next().attr("data-url",res.data[0].url)
					$(that).next().next().next().css({'background':str,"background-size":"100% 100%"})
				},
				error: function() {
					//演示失败状态，并实现重传
					var demoText = $('#demoText');
					demoText.html(
						'<span style="color: #FF5722; ">上传失败</span> <a class="layui-btn layui-btn-xs demo-reload ">重试</a>'
					);
					demoText.find('.demo-reload').on('click', function() {
						uploadInst.upload();
					});
				}
			});
		})
	}
	function deleteQua (str){
		var data = zzlist;
		data.splice(str,1)
		zzlist = data
		addlist()
	}
	function opt(item,key){
		zzlist[key].key = $(item).val()
	}
	function onchg(item,key){
		console.log(item)
		console.log(key)
	}
	//保存
	function saveQualification() {
		let body = {},list = zzlist;
		let obj1 = {},obj2 = {},arr = [];
		var t1 =  $("#txt1").val();
		var t2 =  $("#txt2").val();
		var t3 =  $("#xiaoYan_url").val();
		var t4 = $("#upload3").attr("data-n");
		if(!t1){
			alert("营业执照为必填项!")
			return ;
		}
		if(!t2){
			alert("品牌名称为必填项!")
			return ;
		}
		if(!t3){
			alert("公司网址为必填项!")
			return ;
		}
		if(!t4){
			alert("营业执照必须上传!")
			return ;
		}
//		参数1
		obj1.adBrand =t1
		obj1.adComapyName = t2
		obj1.adComapyUrl = t3
		
//		参数2
		obj2.businessUrl = $("#upload3").attr("data-n");
		obj2.icpUrl = $("#upload4").attr("data-n");
		obj2.taxCertificateUrl = $("#upload5").attr("data-n");
		obj2.organizationQualificationUrl = $("#upload6").attr("data-n");
		obj2.networkLicenseUrl = $("#upload7").attr("data-n");
		obj2.legalPersonUrl = $("#upload8").attr("data-n");
		obj2.medicalInstitutionUrl = $("#upload9").attr("data-n");
		obj2.medicalAdvertisementUrl = $("#upload10").attr("data-n");
		obj2.brandQualification = $("#upload11").attr("data-n");
//		参数3
		for(var i=0;i<list.length;i++){
			var obj = {}
			obj.key = list[i].key
			obj.value = list[i].value
			arr.push(obj)
		}
		body.adUserInfo = obj1;
		body.adUserInfoQualified = obj2;
		body.adUserInfoQualifiedSup = arr;
		let token = sessionStorage.getItem("token");
		$.ajax({
			url: url + "/advertiser/adAptitude/saveOrUpdateAdAptitude",
			type: "post",
			//		参数需转为字符串
			//		json跨域
			dataType: 'json',
			data:JSON.stringify(body),
			async:false,
			//		contentType类型为json
			contentType: "application/json",
			useDefaultXhrHeader: false,
			//		请求头加上X-Token 
			 beforeSend: function(XMLHttpRequest) {
				//		token 为页面所获取
				XMLHttpRequest.setRequestHeader("X-Token", token); 
			},
			success: function(result) {
				layer.msg(result.msg);
				upLoad()
			},
			err: function(err) {
				alert("请求失败");
			}
		});
	}
</script>
<script src="../../oem/js/oem.js"></script>